package com.eco.fanliapp.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.eco.fanliapp.entity.AppOrderDetail;
import com.eco.fanliapp.vo.AppOrderDetailVo;
import com.eco.fanliapp.vo.ChannelUserAffiliationVo;
import com.eco.fanliapp.vo.OrderIntegralCountVo;
import org.apache.ibatis.annotations.Param;

import java.util.HashMap;
import java.util.List;

/**
 * 订单 数据层
 *
 * @author xiaoxx
 * @date 2019-04-24
 */
public interface AppOrderDetailMapper extends BaseMapper<AppOrderDetail> {
    /**
     * 查询订单信息
     *
     * @param orderDetailid 订单ID
     * @return 订单信息
     */
    AppOrderDetail selectAppOrderDetailById(String orderDetailid);

    /**
     * 查询订单列表
     *
     * @param appOrderDetail 订单信息
     * @return 订单集合
     */
    List<AppOrderDetail> selectAppOrderDetailList(AppOrderDetail appOrderDetail);


    List<HashMap<String, Object>> findAppOrderDetail(HashMap<String, Object> hashMap);

    /**
     * 新增订单
     *
     * @param appOrderDetail 订单信息
     * @return 结果
     */
    int insertAppOrderDetail(AppOrderDetail appOrderDetail);

    /**
     * 修改订单
     *
     * @param appOrderDetail 订单信息
     * @return 结果
     */
    int updateAppOrderDetail(AppOrderDetail appOrderDetail);

    /**
     * 删除订单
     *
     * @param orderDetailid 订单ID
     * @return 结果
     */
    int deleteAppOrderDetailById(String orderDetailid);

    /**
     * 批量删除订单
     *
     * @param orderDetailids 需要删除的数据ID
     * @return 结果
     */
    int deleteAppOrderDetailByIds(String[] orderDetailids);

    List<AppOrderDetail> selectAppOrderDetailByKeyWord(@Param("goodsPlatform") String goodsPlatform, @Param("payStatus") String payStatus, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("keyWord") String keyWord, @Param("companyId") Integer companyId);

    List<AppOrderDetailVo> selectAppOrderDetailTkStatus3(@Param("userId") Long userId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetailVo> selectAppOrderDetailTkStatus13(@Param("userId") Long userId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetailVo> selectAppOrderDetailTkStatusNot3And13(@Param("userId") Long userId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetailVo> selectAppOrderDetailTkStatusAll(@Param("userId") Long userId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetailVo> selectJdOrderDetailTkStatus(@Param("userId") Long userId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetailVo> selectPddOrderDetailTkStatus(@Param("userId") Long userId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetail> selectOrderDetailItemISnull();

    List<AppOrderDetail> selectAppOrderDetailByKeyWordWithoutPayStatus(@Param("goodsPlatform") String goodsPlatform, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("keyWord") String keyWord, @Param("companyId") Integer companyId);

    List<AppOrderDetail> selectAppOrderDetailBytradeId(@Param("userId") Long userId, @Param("orderId") Long orderId);

    List<AppOrderDetail> findAppOrderDetailByTaobaoUserId(Long userId);

    Integer selectTotalEffectiveItemCountByTaobaoUserId(Long userId);

    Integer selectTotalRefundItemCountByTaobaoUserId(Long userId);

    Double selectTotalItemCommissionByTaobaoUserId(Long userId);

    /**
     * 查询我的团队下下级订单
     *
     * @param relationId
     * @param specialId
     * @param tkStatus
     * @param start
     * @param back
     * @return
     */
    List<AppOrderDetail> findTeamLeval2OrderLists(@Param("relationId") Long relationId, @Param("specialId") Long specialId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    /**
     * 查询我的团队下级订单
     *
     * @param relationId
     * @param specialId
     * @param tkStatus
     * @param start
     * @param back
     * @return
     */
    List<AppOrderDetail> findTeamLevalOrderLists(@Param("relationId") Long relationId, @Param("specialId") Long specialId, @Param("tkStatus") Integer tkStatus, @Param("start") Integer start, @Param("back") Integer back);

    List<AppOrderDetail> selectAppOrderDetail(AppOrderDetail detail);

    /**
     * 查询所有非失效订单
     *
     * @return
     */
    List<AppOrderDetail> selectAppOrderDetailFailList();

    /**
     * 根据trade查询订单信息
     *
     * @param tradeId 订单ID
     * @return 订单信息
     */
    AppOrderDetail selectAppOrderDetailByTradeId(Long tradeId);

    AppOrderDetail selectAppOrderDetailByTradeIdNew(Long tradeId);

    /**
     * 根据userId查询当天订单数量
     *
     * @param startTodayTime
     * @param endTodayTime
     * @param userId
     * @return
     */
    int selectOrderIsTodayCount(@Param("startTodayTime") long startTodayTime, @Param("endTodayTime") long endTodayTime, @Param("userId") Long userId);

    int selectAppUserOrderCount(Long taobaoUserId);

    /**
     * 0元购单数
     *
     * @param companyId
     * @param flag
     * @param startTime
     * @param endTime
     * @return
     */
    int totalGoodFrees(@Param("companyId") Integer companyId, @Param("flag") Integer flag, @Param("startTime") long startTime, @Param("endTime") long endTime);

    /**
     * 昨日0元购单数
     *
     * @return
     */
    int yesterdayTotalGoodFrees();

    /**
     * 统计订单详情
     *
     * @param hashMap
     * @return
     */
    List<AppOrderDetailVo> findAppOrderDetailNew(HashMap<String, Object> hashMap);

    /**
     * 统计京东订单详情
     *
     * @param hashMap
     * @return
     */
    List<AppOrderDetailVo> findJdAppOrderDetailNew(HashMap<String, Object> hashMap);

    /**
     * 统计拼多多订单详情
     *
     * @param hashMap
     * @return
     */
    List<AppOrderDetailVo> findPddAppOrderDetailNew(HashMap<String, Object> hashMap);

    /**
     * 根据商品详情，查询哪些订单丢失
     *
     * @return
     */
    List<AppOrderDetail> orderCheckList();

    /**
     * 根据商品详情，未处理订单
     *
     * @return
     */
    List<AppOrderDetail> orderCheckUserOrderList();


    /**
     * 查询用户订单详情
     *
     * @param userId
     * @return
     */
    List<AppOrderDetailVo> selectAppOrderDetailListNew(@Param("userId") Long userId);

    int deleteOrderDetail(@Param("orderId") Long orderId);

    /**
     * 根据订单id，用户id查询数量
     *
     * @return
     */
    OrderIntegralCountVo selectDetailByTradeIdAndUserId(@Param("orderId") Long orderId);

    List<ChannelUserAffiliationVo> selectUserListByGoodsId(@Param("goodId") Long goodId, @Param("starTime") Long starTime, @Param("endTime") Long endTime);
}